// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2009-10-26 21:57:27


// Source File Name:   Signature.java

package com.vhly.classfile;

import java.util.Vector;

public class Signature {

    String parameters;
    String returntype;
    String fieldtype;
    int argumentlength;

    public int getArgumentlength() {
        return argumentlength;
    }

    public String getFieldType() {
        return fieldtype;
    }

    public String getParameters() {
        return parameters;
    }

    public String getReturnType() {
        return returntype;
    }

    public Signature(String s) {
        parameters = null;
        returntype = null;
        fieldtype = null;
        argumentlength = 0;
        if (s != null)
            if (s.indexOf("(") == -1) {
                fieldtype = getFieldTypeSignature(s);
            } else {
                Object obj = null;
                if (s.indexOf(")") - 1 > s.indexOf("(")) {
                    String s1 = s.substring(s.indexOf("(") + 1, s.indexOf(")"));
                    parameters = getParametersHelper(s1);
                } else {
                    parameters = "()";
                }
                String s2 = s.substring(s.lastIndexOf(")") + 1);
                returntype = getReturnTypeHelper(s2);
            }
    }

    public String getArrayType(String s) {
        if (s != null) {
            String s1 = "";
            do {
                if (s.indexOf("[") == -1)
                    break;
                s1 = (new StringBuilder()).append(s1).append("[]").toString();
                int i = s.indexOf("[") + 1;
                if (i <= s.length())
                    s = s.substring(i);
            } while (true);
            String s2 = "";
            if (s.startsWith("L"))
                s2 = getObjectType(s);
            else
                s2 = getBaseType(s);
            return (new StringBuilder()).append(s2).append(s1).toString();
        } else {
            return null;
        }
    }

    public String getBaseType(String s) {
        if (s != null) {
            if (s.equals("B"))
                return "byte";
            if (s.equals("C"))
                return "char";
            if (s.equals("D"))
                return "double";
            if (s.equals("F"))
                return "float";
            if (s.equals("I"))
                return "int";
            if (s.equals("J"))
                return "long";
            if (s.equals("S"))
                return "short";
            if (s.equals("Z"))
                return "boolean";
            if (s.equals("V"))
                return "void";
        }
        return null;
    }

    public String getFieldTypeSignature(String s) {
        if (s.startsWith("L"))
            return getObjectType(s);
        if (s.startsWith("["))
            return getArrayType(s);
        else
            return getBaseType(s);
    }

    public String getObjectType(String s) {
        String s1 = "";
        int i = s.indexOf("L") + 1;
        int j = s.indexOf(";");
        if (i != -1 && j != -1) {
            if (i < s.length() && j < s.length())
                s1 = s.substring(i, j);
            s1 = s1.replace('/', '.');
            return s1;
        } else {
            return null;
        }
    }

    public String getParametersHelper(String s) {
        Vector vector = new Vector();
        byte byte0 = -1;
        byte byte1 = -1;
        String s1 = "";
        do {
            if (s == null)
                break;
            if (s.startsWith("L")) {
                int i = s.indexOf("L");
                int j = s.indexOf(";");
                if (i < s.length()) {
                    if (j == s.length() - 1) {
                        s1 = s.substring(i);
                        s = null;
                    } else if (j + 1 < s.length()) {
                        s1 = s.substring(i, j + 1);
                        s = s.substring(j + 1);
                    }
                    vector.add(getObjectType(s1));
                }
            } else if (s.startsWith("[")) {
                String s2 = "";
                int k = -1;
                for (int i1 = 0; i1 < s.length() && s.charAt(i1) == '['; i1++)
                    k = i1;

                if (k + 1 < s.length())
                    s1 = s.substring(0, k + 1);
                int j1 = s.lastIndexOf("[") + 1;
                if (j1 < s.length())
                    s2 = s.substring(j1);
                if (s2.startsWith("L")) {
                    int k1 = s.indexOf("L");
                    int l1 = s.indexOf(";");
                    if (l1 == s.length() - 1) {
                        s1 = (new StringBuilder()).append(s1).append(s.substring(k1)).toString();
                        s = null;
                    } else if (l1 + 1 < s.length()) {
                        s1 = (new StringBuilder()).append(s1).append(s.substring(k1, l1 + 1)).toString();
                        s = s.substring(l1 + 1);
                    }
                } else if (s2.length() == 1) {
                    s1 = (new StringBuilder()).append(s1).append(s2).toString();
                    s = null;
                } else if (s2.length() > 1) {
                    s1 = (new StringBuilder()).append(s1).append(s2.substring(0, 1)).toString();
                    s = s2.substring(1);
                }
                vector.add(getArrayType(s1));
            } else {
                if (s.length() == 1) {
                    s1 = s;
                    s = null;
                } else if (s.length() > 1) {
                    s1 = s.substring(0, 1);
                    s = s.substring(1);
                }
                vector.add(getBaseType(s1));
            }
        } while (true);
        argumentlength = vector.size();
        String s3 = "(";
        for (int l = 0; l < vector.size(); l++) {
            s3 = (new StringBuilder()).append(s3).append((String) vector.elementAt(l)).toString();
            if (l != vector.size() - 1)
                s3 = (new StringBuilder()).append(s3).append(",").toString();
        }

        s3 = (new StringBuilder()).append(s3).append(")").toString();
        return s3;
    }

    public String getReturnTypeHelper(String s) {
        return getFieldTypeSignature(s);
    }
}